<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>清空数组的三种方法</title>
</head>
<body>
    <script>
        // 清空一个数组的三种方法
        // 1.length
        var arr = [1, 2, 3];
        console.log(arr);
        arr.length = 0;
        console.log('arr.length = 0');
        console.log(arr);
        console.log('-------------------');

        // 2.splice
        arr = [1, 2, 3];
        console.log(arr);
        arr.splice(0);
        console.log('arr.splice(0)');
        console.log(arr);
        console.log('-------------------');

        // 3.[]
        arr = [1, 2, 3];
        console.log(arr);
        arr = [];
        console.log('arr = []');
        console.log(arr);
    </script>
</body>
</html>